package com.lzj.demo.design.chain.fzw.chain;

import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.Date;

@Slf4j
@Component
public class AuthChainDemo {
    public void exec(){
        //动态的编排审批责任链:三级审批->二级审批->一级审批
        AuthLink authLink = new Level3AuthLink("1003","李工").setNextAuth(
                            new Level2AuthLink("1002","钱经理").setNextAuth(
                            new Level1AuthLink("1001","赵总")
                    )
               );

        log.info("测试结果:{}", JSONUtil.toJsonStr(authLink.doAuth("Faker","001",new Date())));

        log.info("-->模拟三级审批");
        AuthService.auth("1003","001");
        log.info("测试结果:{}",JSONUtil.toJsonStr(authLink.doAuth("Faker","001",new Date())));

        log.info("-->模拟二级审批");
        AuthService.auth("1002","001");
        log.info("测试结果:{}",JSONUtil.toJsonStr(authLink.doAuth("Faker","001",new Date())));

        log.info("-->模拟一级审批");
        AuthService.auth("1001","001");
        log.info("测试结果:{}",JSONUtil.toJsonStr(authLink.doAuth("Faker","001",new Date())));
    }
}

/**
输出结果:
测试结果:{"code":"001","info":"001 状态:待三级负责人审批 李工"}
-->模拟三级审批
测试结果:{"code":"001","info":"001 状态:待二级负责人审批 钱经理"}
-->模拟二级审批
测试结果:{"code":"001","info":" 状态:待一级负责人审批 赵总"}
-->模拟一级审批
测试结果:{"code":"001","info":" 状态:一级负责人审批完成 时间: 2022-11-11 10:09:02 审批人 赵总"}
*/
